package net.qunzhi.modules.ysweixin.test;

import net.qunzhi.modules.ysweixin.entity.*;
import net.qunzhi.modules.ysweixin.service.WxService;
import net.qunzhi.modules.ysweixin.utils.WxUtils;
import net.sf.json.JSONObject;

public class CreatMenu {

	public static void main(String[] args) {
		
		final String APPID ="wxf9a443e56149361b";
		
		final String SECRET ="5f1bfd6f032fed02b99dc73dec745208";
		
		//菜单对象
		Button bt = new Button();
		
		//第一个有子菜单的菜单
		SubButton sb1 = new SubButton("设备查看");
		sb1.getSub_button().add(new ScancodeButton("扫一扫", "11"));
		sb1.getSub_button().add(new ViewButton("编号查询", "http://www.baidu.com"));
		sb1.getSub_button().add(new ViewButton("保养计划", "http://www.baidu.com"));
		bt.getButton().add(sb1);
		//第二个有子菜单的菜单
		SubButton sb2 = new SubButton("工单管理");
		sb2.getSub_button().add(new ViewButton("提醒记录", "http://lwh.xinglian.info/waterOperation/wechat/authorize?returnUrl=https://www.baidu.com/"));
		sb2.getSub_button().add(new ViewButton("工单查询", "http://www.baidu.com"));
		sb2.getSub_button().add(new ViewButton("创建工单", "http://www.baidu.com"));
		bt.getButton().add(sb2);
		//第三个有子菜单
		SubButton sb3 = new SubButton("我的工单");
		sb3.getSub_button().add(new ViewButton("我创建的", "http://www.baidu.com"));
		sb3.getSub_button().add(new ViewButton("要我检查", "http://www.baidu.com"));
		sb3.getSub_button().add(new ViewButton("要我指派", "http://www.baidu.com"));
		sb3.getSub_button().add(new ViewButton("我接的单", "http://www.baidu.com"));
		sb3.getSub_button().add(new PhotoOrAlumButton("传图", "31"));
		bt.getButton().add(sb3);
		JSONObject jsonObject = JSONObject.fromObject(bt);
		System.out.println(jsonObject.toString());
		//post得地址
		String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
		url = url.replace("ACCESS_TOKEN", WxService.getAccessToken(APPID,SECRET));
		String post = WxUtils.post(url, jsonObject.toString());
		System.out.println(post);
		
	}
}
